<?php
if (!function_exists('mylog'))
{

/*0.2
**author:mof
**in:data: 调试的数据
UserName: 调试者名称,数据的信息会写在temp目录下生"UserName_check.htm"文件
memo: 摘要
method: 写文件方法,传'w'则覆盖,传'a'则续写
**out:成功返回字符串,失败返回false
**memo:写文件函数,仅作调试用,写文件成功后用web查看UserName_check.htm即可
*/
function mylog($data, $memo='None',$method="a")
{
/********************配置区域***************************/
$debugFlag = 1;//调试标识. 0=>不记录, 1=>记录
$cacheFile = dirname(__FILE__).'/debug.html';//debug文件存放地址
$oldContent = '';
/********************配置区域 end***************************/

if($debugFlag == 0)return 0;
$DebugFilePath = $_SERVER["PHP_SELF"];
$header = '<!doctype html><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>DEBUGING LOG</title><script src="http://7xj184.com2.z0.glb.qiniucdn.com/themesjs/jquery-1.4.2.min.js" type="text/javascript"></script>';
$sStyle = <<<EOT
<style type="text/css">
body {
margin: 0px;
padding: 0px;
height: 100%;
}

body, th, td {
font-family: Tahoma, Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
color: #333;
}
</style>
EOT;
$sScript = <<<EOT
<script>
\$(function() {
var _oMemo = {all:{label:'all', total:$("div.block").length}};
\$("div.block").each(function(){
if(typeof _oMemo[$(this).attr('_k')] == 'undefined')
_oMemo[$(this).attr('_k')] = {};
if(typeof _oMemo[$(this).attr('_k')]['total'] == 'undefined'){
_oMemo[$(this).attr('_k')]['total'] = 1;
_oMemo[$(this).attr('_k')]['label'] = $(this).attr('_l');
}else
_oMemo[$(this).attr('_k')]['total'] += 1;
})
var sUl = "";
for(var k in _oMemo){
sUl += '<li><a _k="'+k+'" href="javascript:void()" >'+_oMemo[k]['label']+'('+_oMemo[k]['total']+')</a></li>';
}
$('div#tabs').html("<ul>"+sUl+"</ul><div  style=\"position:absolute;top:10px;right:20px;\" class='allinfoSwith'><a href='javascript:void()' >全部 展开/收起</a></div>");
$('div#tabs li a').click(function(){
var _showK = $(this).attr('_k');
if(_showK == 'all'){
$('div.block').show();
}else{
$('div.block').hide();
$('div.block[_k="'+_showK+'"]').show();
}
});
$('div.block span.infoswitch a').click(function(){
var _o = $(this).parents('div.block').find('div.info').eq(0);
_o.toggle();
});
var allinfoSwithIndex = 0;
$('div.allinfoSwith a').click(function(){
allinfoSwithIndex%2==0 ? $('div.info').hide() : $('div.info').show();
allinfoSwithIndex++;
});
//\$( "#tabs" ).tabs();
});
</script>
EOT;
if(!file_exists($cacheFile) || $method=='w'){

$oldContent = $header.$sStyle.'</head><body><div id="tabs"></div></body></html>'.$sScript;
}
else{
$oldContent = (file_exists($cacheFile)) ? file_get_contents($cacheFile) : "";
}

if(strpos($oldContent, "</div></body></html>") == false) {
    $oldContent =  $header.$sStyle.'</head><body><div id="tabs"></div></body></html>'.$sScript . $oldContent;
}
$sBlockHTML = "\n\n\n<div class='block' _k='".md5($memo)."' _l='".$memo."'><span style='display:none'><------orderIndex-------></span>";
$orderIndex = substr_count($oldContent, '<------orderIndex------->');
list($em,$es) = explode(' ',microtime());
$timespan = (float)$em + (float)$es;
$str = '';
$str .= $oldContent;
$str .= $sBlockHTML;
$str .= "<span  class='no' style='color:blue;'>NO</span>:\t".++$orderIndex."\n\n";
$str .= "<span  style='color:blue;'>Timespan</span>:\t".$timespan."\n\n";
$str .= "\t<span  style='color:blue;'>Date</span>:\t".date("Y-m-d H:i:s")."\n";
$str .= "\t<span  style='color:blue;'>File</span>:\t".$DebugFilePath."\n";
$str .= "<br/><span class='memo' style='color:blue;'>Memo</span>:\t".$memo."<br>\n";
$str .= "----------------------------------------<span class='infoswitch'><a  href='javascript:void()' >展开/收起</a></span>\n<div class='info'>";
ob_start();
if(is_array($data))
print_r($data);
elseif(is_string($data))
echo $data;
else
var_dump($data);
$a = ob_get_contents();
ob_end_clean();
$str .= "<xmp>";
$str .=$a;
$str .= "</xmp>";
$str .= "</div>\n<hr></div>\n\n\n";
//$oldContent = str_replace("</body>", $str."</body>", $oldContent);
try{
    file_put_contents($cacheFile, $str);
} catch (Exception $ex) {
    
}

return 1;

}
}

if (!function_exists('mylogger'))
{

/*0.2
**author:mof
**in:data: 调试的数据
UserName: 调试者名称,数据的信息会写在temp目录下生"UserName_check.htm"文件
memo: 摘要
method: 写文件方法,传'w'则覆盖,传'a'则续写
**out:成功返回字符串,失败返回false
**memo:写文件函数,仅作调试用,写文件成功后用web查看UserName_check.htm即可
*/
function mylogger($data, $memo='None',$method="a")
{
/********************配置区域***************************/
$debugFlag = 1;//调试标识. 0=>不记录, 1=>记录
$cacheFile = dirname(__FILE__).'/log/log'.  date("Ymd") .'.html';//debug文件存放地址
$oldContent = '';
/********************配置区域 end***************************/

if($debugFlag == 0)return 0;
$DebugFilePath = $_SERVER["PHP_SELF"];
$header = '<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>DEBUGING LOG</title><script src="http://4g.100med.com.cn/themes/lefeng/js/jquery-1.4.2.min.js" type="text/javascript"></script>';
$sStyle = <<<EOT
<style type="text/css">
body {
margin: 0px;
padding: 0px;
height: 100%;
}

body, th, td {
font-family: Tahoma, Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
color: #333;
}
</style>
EOT;
$sScript = <<<EOT
<script>
\$(function() {
var _oMemo = {all:{label:'all', total:$("div.block").length}};
\$("div.block").each(function(){
if(typeof _oMemo[$(this).attr('_k')] == 'undefined')
_oMemo[$(this).attr('_k')] = {};
if(typeof _oMemo[$(this).attr('_k')]['total'] == 'undefined'){
_oMemo[$(this).attr('_k')]['total'] = 1;
_oMemo[$(this).attr('_k')]['label'] = $(this).attr('_l');
}else
_oMemo[$(this).attr('_k')]['total'] += 1;
})
var sUl = "";
for(var k in _oMemo){
sUl += '<li><a _k="'+k+'" href="javascript:void()" >'+_oMemo[k]['label']+'('+_oMemo[k]['total']+')</a></li>';
}
$('div#tabs').html("<ul>"+sUl+"</ul><div  style=\"position:absolute;top:10px;right:20px;\" class='allinfoSwith'><a href='javascript:void()' >全部 展开/收起</a></div>");
$('div#tabs li a').click(function(){
var _showK = $(this).attr('_k');
if(_showK == 'all'){
$('div.block').show();
}else{
$('div.block').hide();
$('div.block[_k="'+_showK+'"]').show();
}
});
$('div.block span.infoswitch a').click(function(){
var _o = $(this).parents('div.block').find('div.info').eq(0);
_o.toggle();
});
var allinfoSwithIndex = 0;
$('div.allinfoSwith a').click(function(){
allinfoSwithIndex%2==0 ? $('div.info').hide() : $('div.info').show();
allinfoSwithIndex++;
});
//\$( "#tabs" ).tabs();
});
</script>
EOT;
if(!file_exists($cacheFile) || $method=='w'){
    $oldContent = $header.$sStyle.'</head><body><div id="tabs"></div></body></html>'.$sScript;
}
else{
    $oldContent = (file_exists($cacheFile)) ? file_get_contents($cacheFile) : "";
}
if(strpos($oldContent, "</div></body></html>") == false) {
    $oldContent =  $header.$sStyle.'</head><body><div id="tabs"></div></body></html>'.$sScript . $oldContent;
}
$sBlockHTML = "\n\n\n<div class='block' _k='".md5($memo)."' _l='".$memo."'><span style='display:none'><------orderIndex-------></span>";
$orderIndex = substr_count($oldContent, '<------orderIndex------->');
list($em,$es) = explode(' ',microtime());
$timespan = (float)$em + (float)$es;
$str = '';
$str .= $oldContent;
$str .= $sBlockHTML;
$str .= "<span  class='no' style='color:blue;'>NO</span>:\t".++$orderIndex."\n\n";
$str .= "<span  style='color:blue;'>Timespan</span>:\t".$timespan."\n\n";
$str .= "\t<span  style='color:blue;'>Date</span>:\t".date("Y-m-d H:i:s")."\n";
$str .= "\t<span  style='color:blue;'>File</span>:\t".$DebugFilePath."\n";
$str .= "<br/><span class='memo' style='color:blue;'>Memo</span>:\t".$memo."<br>\n";
$str .= "----------------------------------------<span class='infoswitch'><a  href='javascript:void()' >展开/收起</a></span>\n<div class='info'>";
ob_start();
if(is_array($data))
print_r($data);
elseif(is_string($data))
echo $data;
else
var_dump($data);
$a = ob_get_contents();
ob_end_clean();
$str .= "<xmp>";
$str .=$a;
$str .= "</xmp>";
$str .= "</div>\n<hr></div>\n\n\n";
//$oldContent = str_replace("</body>", $str."</body>", $oldContent);
try{
    file_put_contents($cacheFile, $str);
} catch (Exception $ex) {
    
}

return 1;

}
}
if (!function_exists('mylogsql'))
{

/*0.2
**author:mof
**in:data: 调试的数据
UserName: 调试者名称,数据的信息会写在temp目录下生"UserName_check.htm"文件
memo: 摘要
method: 写文件方法,传'w'则覆盖,传'a'则续写
**out:成功返回字符串,失败返回false
**memo:写文件函数,仅作调试用,写文件成功后用web查看UserName_check.htm即可
*/
function mylogsql($data, $memo='None',$method="a")
{
/********************配置区域***************************/
$debugFlag = 1;//调试标识. 0=>不记录, 1=>记录
$cacheFile = dirname(__FILE__).'/mysql/sqlerr'.date("Ymd").'.html';//debug文件存放地址
$oldContent = '';
/********************配置区域 end***************************/

if($debugFlag == 0)return 0;
$DebugFilePath = $_SERVER["PHP_SELF"];


$header = '<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>DEBUGING LOG</title><script src="http://4g.100med.com.cn/themes/lefeng/js/jquery-1.4.2.min.js" type="text/javascript"></script>';
$sStyle = <<<EOT
<style type="text/css">
body {
margin: 0px;
padding: 0px;
height: 100%;
}

body, th, td {
font-family: Tahoma, Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
color: #333;
}
</style>
EOT;
$sScript = <<<EOT
<script>
\$(function() {
var _oMemo = {all:{label:'all', total:$("div.block").length}};
\$("div.block").each(function(){
if(typeof _oMemo[$(this).attr('_k')] == 'undefined')
_oMemo[$(this).attr('_k')] = {};
if(typeof _oMemo[$(this).attr('_k')]['total'] == 'undefined'){
_oMemo[$(this).attr('_k')]['total'] = 1;
_oMemo[$(this).attr('_k')]['label'] = $(this).attr('_l');
}else
_oMemo[$(this).attr('_k')]['total'] += 1;
})
var sUl = "";
for(var k in _oMemo){
sUl += '<li><a _k="'+k+'" href="javascript:void()" >'+_oMemo[k]['label']+'('+_oMemo[k]['total']+')</a></li>';
}
$('div#tabs').html("<ul>"+sUl+"</ul><div  style=\"position:absolute;top:10px;right:20px;\" class='allinfoSwith'><a href='javascript:void()' >全部 展开/收起</a></div>");
$('div#tabs li a').click(function(){
var _showK = $(this).attr('_k');
if(_showK == 'all'){
$('div.block').show();
}else{
$('div.block').hide();
$('div.block[_k="'+_showK+'"]').show();
}
});
$('div.block span.infoswitch a').click(function(){
var _o = $(this).parents('div.block').find('div.info').eq(0);
_o.toggle();
});
var allinfoSwithIndex = 0;
$('div.allinfoSwith a').click(function(){
allinfoSwithIndex%2==0 ? $('div.info').hide() : $('div.info').show();
allinfoSwithIndex++;
});
//\$( "#tabs" ).tabs();
});
</script>
EOT;
if(!file_exists($cacheFile) || $method=='w'){
$oldContent = $header.$sStyle.'</head><body><div id="tabs"></div></body></html>'.$sScript;
}
else{
$oldContent = (file_exists($cacheFile)) ? file_get_contents($cacheFile) : "";
}
if(strpos($oldContent, "</div></body></html>") == false) {
    $oldContent =  $header.$sStyle.'</head><body><div id="tabs"></div></body></html>'.$sScript . $oldContent;
}
$sBlockHTML = "\n\n\n<div class='block' _k='".md5($memo)."' _l='".$memo."'><span style='display:none'><------orderIndex-------></span>";
$orderIndex = substr_count($oldContent, '<------orderIndex------->');
list($em,$es) = explode(' ',microtime());
$timespan = (float)$em + (float)$es;
$str = '';
$str .= $oldContent;
$str .= $sBlockHTML;
$str .= "<span  class='no' style='color:blue;'>NO</span>:\t".++$orderIndex."\n\n";
$str .= "<span  style='color:blue;'>Timespan</span>:\t".$timespan."\n\n";
$str .= "\t<span  style='color:blue;'>Date</span>:\t".date("Y-m-d H:i:s")."\n";
$str .= "\t<span  style='color:blue;'>File</span>:\t".$DebugFilePath."\n";
$str .= "<br/><span class='memo' style='color:blue;'>Memo</span>:\t".$memo."<br>\n";
$str .= "----------------------------------------<span class='infoswitch'><a  href='javascript:void()' >展开/收起</a></span>\n<div class='info'>";
ob_start();
if(is_array($data))
print_r($data);
elseif(is_string($data))
echo $data;
else
var_dump($data);
$a = ob_get_contents();
ob_end_clean();
$str .= "<xmp>";
$str .=$a;
$str .= "</xmp>";
$str .= "</div>\n<hr></div>\n\n\n";
//$oldContent = str_replace("</body>", $str."</body>", $oldContent);
try{
    file_put_contents($cacheFile, $str);
} catch (Exception $ex) {
    
}
return 1;

}
}